package com.ms.controller;


import com.ms.common.Result;
import com.ms.pojo.Leave_apply;
import com.ms.service.AdminLeaveService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admins")
@Tag(name = "管理员批假接口")
public class AdminLeaveController {
    @Autowired
    private AdminLeaveService adminLeaveService;
    /**
     * 获取所有未审批的请假记录
     */
    @GetMapping("/list")
    @Operation(summary = "获取未审批的请假记录")
    public Result<List<Leave_apply>> list() {
        return Result.success(adminLeaveService.list());
    }

    /**
     * 根据ID获取请假详情
     */
    @GetMapping("/getById")
    @Operation(summary = "根据ID查询请假")
    public Result<Object> getById(Integer id) {
        return Result.success(adminLeaveService.getById(id));
    }
    /**
     * 更新请假状态（审批操作）
     */
    @GetMapping("/updateStatus")
    @Operation(summary = "更新请假状态（审批）")
    public Result<Object> updateStatus(
            @Parameter(description = "请假记录ID", required = true) @NotNull Integer id,
            @Parameter(description = "审批状态（1-通过，2-拒绝）", required = true) @NotNull Integer status,
            @Parameter(description = "审批人ID", required = true) @NotNull Integer approverId,
            @Parameter(description = "审批意见") String approvalOpinion) {

        // 可选：添加额外的状态合法性检查

        boolean success = adminLeaveService.updateStatus(id, status, approverId, approvalOpinion);
        return success ? Result.success("审批成功") : Result.error("审批失败");
    }
}
